/*
 *  Copyright 2012 Iurii Dunko, Iana Potochniak.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.yyminijava.util;

import java.util.ArrayList;
import java.util.List;

/**
 * Simple (UNIX like) command line arguments parser.
 * I understand only flags that can be combined and clean arguments.
 * Flags start from '-'.
 * "-fs arg1" means the same as "-f -s arg1" and the same as "arg1 -fs".   
 * @author Iurii Dunko
 * @author Iana Potochniak
 */
public class ArgsParserr {

	private String flags = "";
	private List<String> args = new ArrayList<String>();
	
	public ArgsParserr(String args[]) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < args.length; i++) {
			if (args[i].startsWith("-")){
				// we process flags sequence
				sb.append(args[i].substring(1));
			} else {
				// we process arguments
				this.args.add(args[i]);
			}
		}
		flags = sb.toString();
	}
	
	public boolean contains(char flag){
		return flags.indexOf(flag) != -1;
	}
	
	public boolean conatinsBoth(char flag1, char flag2){
		return flags.indexOf(flag1) != -1 && flags.indexOf(flag2) != -1;
	}
	
	public String getArg(int index){
		if (args.size() <= index){
			return null;
		}
		return args.get(index);
	}
}
